package net.zjitc.android2019.ch3storage;

import android.content.Context;
import android.content.SharedPreferences;

import java.util.HashMap;

/**
 * 将账号密码保存在SharePreferences，
 * 获取sp中的账号密码并返回
 * */
/**
 * context 代表上下文对象
 * name 账号
 * pwd 密码
 * 保存成功返回ture
 * */
public class SPSaveQQ {
    public static boolean sava(Context context, String name, String pwd) {
        SharedPreferences sp = context.getSharedPreferences("qq",Context.MODE_PRIVATE);
        SharedPreferences.Editor editor=sp.edit();
        editor.putString("name",name);
        editor.putString("pwd",pwd);
        editor.commit();
        return true;
    }

    public static HashMap<String, String> get(Context context) {
        HashMap<String,String> hashMap = new HashMap<String,String>();
        SharedPreferences sp = context.getSharedPreferences("qq",Context.MODE_PRIVATE);
        String name = sp.getString("name",null);
        String pwd = sp.getString("pwd",null);
        hashMap.put("name",name);
        hashMap.put("pwd",pwd);
        return hashMap;
    }
}
